﻿using OnlineAuction.Business;
using OnlineAuction.Entity;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace OnlineAuction
{
    public partial class ChangeProfile : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (Request.Cookies["UserInfo"] == null)
            {
                Response.Redirect("Home.aspx");
            }
            if (!IsPostBack)
            {
                UserBO bo = new UserBO();
                var user = bo.GetUser(Request.Cookies["UserInfo"]["UserName"].ToString());
                txtFullName.Text = user.UserFullName;
                if (user.UserGender.CompareTo("1") == 0 || user.UserGender.CompareTo("True") == 0)
                {
                    rbtGender.SelectedValue = "1";
                }
                else
                {
                    rbtGender.SelectedValue = "0";
                }
                txtPhoneNumber.Text = user.UserPhoneNumber;
                txtIdentityCard.Text = user.UserIdentityCard;
                txtEmail.Text = user.UserEmail;
                txtAddress.Text = user.UserAddress;
            }
        }

        protected void btnReset_Click(object sender, EventArgs e)
        {
            txtAddress.Text = "";
            txtEmail.Text = "";
            txtFullName.Text = "";
            txtIdentityCard.Text = "";
            txtPhoneNumber.Text = "";
        }

        protected void btnAddUser_Click(object sender, EventArgs e)
        {
            UserBO bo = new UserBO();
            //create new User entity
            UserDTO u = new UserDTO(Request.Cookies["UserInfo"]["UserName"].ToString()
                , "", txtFullName.Text, rbtGender.SelectedValue, txtPhoneNumber.Text,
                txtAddress.Text, txtEmail.Text, txtIdentityCard.Text);
            //Check result add item
            bool flag = bo.UpdateProfile(u);
            if (flag)
            {
                Response.Redirect("UserInfo.aspx");
            }
        }
    }
}